package leetcode.字符串;

public class Leetcode5 {
    public String longestPalindrome(String s) {
        if(s.length()==0||s.length()==1){
            return s;
        }
        String max = "";
        for (int i = 0; i < s.length()-1; i++) {
            String s1 = palindromeString(s,i,i);
            String s2 = palindromeString(s,i,i+1);
            String maxString = s1.length()>s2.length()?s1:s2;
            max = maxString.length()>max.length()?maxString:max;
        }
        return max;
    }

    public String palindromeString(String s,int start,int end){
        while(start>=0&&end<s.length()){
            if(s.charAt(start)==s.charAt(end)){
                start--;
                end++;
            }else{
                break;
            }
        }
        return s.substring(start+1,end);
    }
}
